
package com.aditya.personalexpense;

import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;

import com.aditya.personalexpense.controls.PagerSlidingTabStrip;
import com.aditya.personalexpense.fragments.InputFragment;

public class HomeActivity extends BaseFragmentActivity 
{


	private PagerSlidingTabStrip tabs;
	private ViewPager pager;
	private MyPagerAdapter adapter;

	private int tabColor = Color.parseColor("#FFC74B46");
	private View view;
	
	@Override
	public void initial()
	{
		view =  inflater.inflate(R.layout.home_activity,null);
		llMiddle.addView(view,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		initializeControls();
		initActionBar();


	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) 
	{

		switch (item.getItemId()) 
        {
            case R.id.Search:
//            		startActivity(new Intent(getApplicationContext(), SearchActivity.class));
                return true;
            case R.id.Settings:
            		startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }

	}


	
	private void initializeControls()
	{
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		pager = (ViewPager) findViewById(R.id.pager);
		adapter = new MyPagerAdapter(getSupportFragmentManager());

		pager.setAdapter(adapter);

		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
		pager.setPageMargin(pageMargin);
		tabs.setViewPager(pager);
		tabs.setIndicatorColor(tabColor);
	}
	
	private void initActionBar()
	{
		ActionBar actionBar = getActionBar();
	    actionBar.setCustomView(R.layout.action_bar_view);
	    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM|ActionBar.DISPLAY_SHOW_HOME);


	    actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);
        

	}


	public class MyPagerAdapter extends FragmentPagerAdapter 
	{

		private final String[] TITLES = { "Input","Summary","History"};

		public MyPagerAdapter(FragmentManager fm) 
		{
			super(fm);
		}

		@Override
		public CharSequence getPageTitle(int position) 
		{
			return TITLES[position];
		}

		@Override
		public int getCount() 
		{
			return TITLES.length;
		}

		@Override
		public Fragment getItem(int position) 
		{
			return InputFragment.newInstance(position);
		}

	}

}